home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Utitlities.c
-
- Contains: General utility routines
-
- Written by: Chris White, Developer Technical Support
-
- Copyright: © 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- 03/29/96 CW First release
-
- */
-
-
- #pragma segment Core
-
-
-
- // System Includes
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
-
- #ifndef __CODEFRAGMENTS__
- #include <CodeFragments.h>
- #endif
-
-
- // Application Includes
-
- #ifndef __BAREBONES__
- #include "BareBones.h"
- #endif
-
- #ifndef __PROTOTYPES__
- #include "Prototypes.h"
- #endif
-
-
-
-
-
- StringPtr CopyPStr ( Str255 inSourceStr, StringPtr outDestStr, SInt16 inDestSize )
- {
- SInt8 dataLen = inSourceStr[0] + 1;
-
- if ( dataLen > inDestSize )
- dataLen = inDestSize;
- BlockMoveData ( inSourceStr, outDestStr, dataLen );
- outDestStr[0] = dataLen - 1;
-
- return outDestStr;
- }
-
-
-
- StringPtr ConcatPStr ( Str255 ioFirstStr, Str255 inSecondStr, SInt16 inDestSize )
- {
- SInt8 charsToCopy = inSecondStr[0];
-
- if ( ioFirstStr[0] + charsToCopy > inDestSize - 1 )
- charsToCopy = inDestSize - 1 - ioFirstStr[0];
- BlockMoveData ( inSecondStr + 1, ioFirstStr + ioFirstStr[0] + 1, charsToCopy );
- ioFirstStr[0] += charsToCopy;
-
- return ioFirstStr;
- }
-
-
-
- void OSTypeToPStr ( OSType inOSType, StringPtr outString )
- {
- BlockMoveData ( &inOSType, outString + 1, sizeof ( OSType ) );
- outString[0] = sizeof ( OSType );
-
- return;
- }
-
-
-
- void PStrToOSType ( StringPtr inString, OSType* outOSType )
- {
- BlockMoveData ( inString + 1, outOSType, sizeof ( OSType ) );
-
- return;
- }
-
-
-
- //
- // Tell the user that something went wrong
- //
- void AlertUser ( SInt16 messageCode, SInt16 errorNum, StringPtr theString )
- {
- Str255 messageString;
- Str255 numberString;
-
- if ( messageCode > 0 )
- GetIndString ( messageString, kErrorStrings, messageCode );
- else
- messageString[0] = '\0';
-
- if ( errorNum != 0 )
- NumToString ( errorNum, numberString );
- else
- numberString[0] = '\0';
-
- ParamText ( messageString, numberString, theString, (StringPtr) "\p" );
-
- StopAlert ( kErrorDialog, nil );
-
- // We need to clear the param text so it isn't used by mistake
- ParamText ( (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p" );
-
- return;
- }
-
-
-
- void LocalToGlobalRect ( Rect* theRect )
- {
- LocalToGlobal ( (Point*) &theRect->top );
- LocalToGlobal ( (Point*) &theRect->bottom );
-
- return;
- }
-
-
-
- Boolean IsMovableModal ( WindowRef theWindow )
- {
- return (GetWVariant ( theWindow ) == movableDBoxProc);
- }
-
-
-
- #if DEBUGGING
- void DebugStrNum ( Str255 str, SInt32 num )
- {
- Str255 debug_str, tmp_str;
-
- BlockMoveData ( &str[0], &debug_str[0], str[0] + 1 );
-
- NumToString ( num , &tmp_str[0] );
- debug_str[debug_str[0] + 1] = ' ';
- BlockMoveData ( &tmp_str[1], &debug_str[debug_str[0] + 2], tmp_str[0] );
- debug_str[0] = debug_str[0] + tmp_str[0] + 1;
- DebugStr ( debug_str );
-
- return;
- }
- #endif
-
-
-